set(target_name ql_qlib)


set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# SRC文件
file(GLOB_RECURSE SRC_FILES src/*.cpp)
add_library(${target_name} SHARED ${SRC_FILES})

# H文件
target_include_directories(${target_name} PRIVATE 
    ${CMAKE_CURRENT_SOURCE_DIR}/include
    ${QLAYOUT_SDK_DIR}/include
    # ${VCPKG_SDK}/include/qt5
)

target_compile_definitions(${target_name} PRIVATE QLIB_EXPORTS)

find_package(ql_dxfrw REQUIRED)
find_package(ql_klayout_utils REQUIRED)
find_package(Qt5 COMPONENTS Core Widgets Network Sql Concurrent Xml REQUIRED CONFIG)
find_package(Clipper2 REQUIRED)
find_package(RapidJSON REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(freetype REQUIRED)
find_package(spdlog REQUIRED)
find_package(EnTT REQUIRED)
find_package(vsg REQUIRED)

target_link_libraries(${target_name} PRIVATE ql_dxfrw)
target_link_libraries(${target_name} PRIVATE ql_klayout_utils)
target_link_libraries(${target_name} PRIVATE Qt5::Core Qt5::Widgets Qt5::Network Qt5::Sql Qt5::Concurrent Qt5::Xml)
target_link_libraries(${target_name} PRIVATE Clipper2::clipper2 Clipper2::clipper2z)
target_link_libraries(${target_name} PRIVATE rapidjson)
target_link_libraries(${target_name} PRIVATE nlohmann_json::nlohmann_json)
target_link_libraries(${target_name} PRIVATE Freetype::Freetype)
target_link_libraries(${target_name} PRIVATE spdlog::spdlog)
target_link_libraries(${target_name} PRIVATE EnTT::EnTT)
target_link_libraries(${target_name} PRIVATE vsg::vsg)



# 安装配置
install(TARGETS ql_qlib
    EXPORT ql_qlibTargets
    RUNTIME DESTINATION bin
    ARCHIVE DESTINATION lib
    PUBLIC_HEADER DESTINATION include
)

install(DIRECTORY include/qlib DESTINATION include)
# if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# else()
# endif()

# 生成配置文件
install(EXPORT ql_qlibTargets
    FILE ql_qlibTargets.cmake
    DESTINATION lib/cmake/ql_qlib
)

include(CMakePackageConfigHelpers)
configure_package_config_file(
    ${CMAKE_CURRENT_SOURCE_DIR}/ql_qlibConfig.cmake.in
    ${CMAKE_CURRENT_BINARY_DIR}/ql_qlibConfig.cmake
    INSTALL_DESTINATION lib/cmake/ql_qlib
)

install(FILES 
    ${CMAKE_CURRENT_BINARY_DIR}/ql_qlibConfig.cmake
    DESTINATION lib/cmake/ql_qlib
)

